-- damage
-- create by weism
-- 攻击受创（技能规则）

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 威力
        local force = para[1];

        local prop = PropM.combine(source, "power_resonance", skillId);
        if prop[3] > 0 then
            force = PropM.trigger(source, prop[1], prop[2], force);
        end

        -- 2. 攻击方的魔力
        local attack = source:getAttack();

        -- 被对方百分比削弱
        prop = PropM.combine(target, "weak_enemy", "attack");
        attack = PropM.apply(prop, attack);

        -- 被对方绝对值削弱
        prop = PropM.combine(target, "weak_enemy2", "attack");
        attack = PropM.apply(prop, attack);

        -- 3. 伤害/计算伤害时魔力+3
        local damage = math.modf(force * attack / 1000);

        if #para > 1 and tonumber(para[2]) == target.style then
            -- 该系别有伤害加成
            damage = math.modf(para[3] * damage / 1000);
        end

        -- 被敌方百分比削弱
        prop = PropM.combine(target, "weak_damage_mon", skillId);
        if prop[3] > 0 then
            damage = math.max(FormulaM.invoke("CALC_BIG_DIVISION", damage, 1000 - prop[3], 1000), 1);
        end

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 被辅助了（光环怪）,在场时，全场同伴攻击附加吸血效果
        prop = PropM.combine(source, "aid_absorb", 1);
        if prop[3] > 0 then
            local hp = PropM.apply(prop, damage);
            CombatM.receiveCure(source, source, hp);
        end

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        if (#arr == 1) then
            return { tonumber(arr[1]), };
        else
            return { tonumber(arr[1]), arr[2], tonumber(arr[3]) };
        end
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 威力
        local force = para[1];

        -- 2. 攻击方的魔力
        local attack = source:getAttack();

        -- 3. 伤害
        local damage = math.modf(force * attack / 1000);

        desc = string.gsub(desc, "{damage_mon}", damage);

        -- 系别TODO

        return desc;
    end,
};
